<?php
include_once('shopObject.php');
/**
 * mdl_packet
 *
 * @uses shopObject
 * @package
 * @version $Id: mdl.packet.php 1867 2008-04-23 04:00:24Z hujianxin $
 * @copyright 2008-2010 alone
 * @license Commercial
 */
class mdl_packet extends shopObject{

    var $idColumn = 'packet_id';
    var $textColumn = 'packet_name';
    var $adminCtl = 'content/packet';
    var $defaultCols = 'packet_name,packet_href,uptime,ifpub,orderlist';
    var $defaultOrder = array('orderlist','desc');
    var $tableName = 'sdb_packet';

    function getColumns()
	{
        return array(
				//'packet_id'=>array('label'=>'数据包id','class'=>'span-4'),    /* 数据包id */
				'packet_name'=>array('label'=>'数据包名称','class'=>'span-5','required'=>1),    /* 数据包名称 */
				'packet_href'=>array('label'=>'数据包地址','class'=>'span-6','required'=>1),    /* 数据包地址 */
				'uptime'=>array('label'=>'更新时间','class'=>'span-6','type'=>'time'),    /* 更新时间 */
				'content'=>array('label'=>'描述','class'=>'span-7'),		/* 描述 */
				'ifpub'=>array('label'=>'是否显示','class'=>'span-6','type'=>'bool'),    /* 是否发布 1发布 0不发布*/
				'orderlist'=>array('label'=>'排序','class'=>'span-7','type'=>'number')	/* 排序 */
        );
    }

    function getFieldById($packet_id, $aField=array('*'))
	{
        $sqlString = 'SELECT '.implode(',', $aField).' FROM sdb_packet WHERE packet_id = '.intval($packet_id);
        return $this->db->selectrow($sqlString);
    }

	function getList($cols, $filter, $start=0, $limit=20, &$count, $orderType=null)
	{
		$sql = 'SELECT '.$cols.' FROM sdb_packet WHERE '.$this->_filter($filter);
		if ($orderType)
		{
			$sql .= 'ORDER BY '.implode(' ', $orderType);
		}
		$count = $this->db->_count($sql);
		return $this->db->selectLimit($sql, $limit, $start);
	}

	function _filter($filter)
	{
		return parent::_filter($filter);
	}

    function save($aData, &$msg)
	{
        if($aData['packet_id'])
		{
            $rs = $this->db->query("SELECT * FROM " . $this->tableName . " WHERE packet_id=" . intval($aData['packet_id']));
            $sql = $this->db->getUpdateSql($rs,$aData);
        }
		else
		{
            $rs = $this->db->query("SELECT * FROM " . $this->tableName . " WHERE 0=1");
            $sql = $this->db->getInsertSql($rs,$aData);
        }

        if($this->db->exec($sql))
		{
            $msg = "保存成功";
            return true;
        }
		else
		{
            $msg = "保存失败";
            return false;
        }
    }
}